package com.golang.api.service.impl;


import com.golang.api.domain.Tag;
import com.golang.api.dto.request.TagInfoDto;
import com.golang.api.dto.request.TagSearchDto;
import com.golang.api.dto.response.TagListRespDto;
import com.golang.api.repository.TagRepository;
import com.golang.api.service.ITagService;
import com.golang.api.util.Result;
import com.golang.api.util.ResultGenerator;
import org.springframework.stereotype.Service;

import java.util.List;
import javax.annotation.Resource;

/**
 * 标签Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-12
 */
@Service
public class TagServiceImpl implements ITagService {

    @Resource
    TagRepository tagRepository;


    @Override
    public Result<TagListRespDto> list(TagSearchDto query) {

        List<Tag> list = tagRepository.queryTag(query);
        TagListRespDto respDto = new TagListRespDto();
        respDto.setList(listInfos2Items(list).apply(list));
        return ResultGenerator.success(respDto);

    }

    @Override
    public Result<Long> create(TagInfoDto info) {

        Tag tag = TagInfoDto2Tag(info).apply(info);
        boolean insertFlag = tagRepository.insertTagInfo(tag) > 0;
        if (insertFlag) {

            return ResultGenerator.success(tag.getId());
        }
        return null;
    }
}
